<?php
App::uses('AppModel', 'Model');
/**
 * Supplier Model
 *
 */
class Supplier extends AppModel {

  
    public $displayField = 'supplierName';
/**
 * Validation rules
 *
 * @var array
 */
    public $validate = array(
        'supplierName' => array(
            'notempty' => array(
                'rule' => array('notempty'),
                'message' => 'Please enter a supplier name',
                //'allowEmpty' => false,
                //'required' => false,
                //'last' => false, // Stop validation after this rule
                //'on' => 'create', // Limit validation to 'create' or 'update' operations
            ),
        ),
        'contactPersonName' => array(
            'notempty' => array(
                'rule' => array('notempty'),
                'allowEmpty' => true,
                'required' => false,
                'message' => 'Please enter the name of a contact person ',
                
                //'last' => false, // Stop validation after this rule
                //'on' => 'create', // Limit validation to 'create' or 'update' operations
            ),
        ),
       
            
        'phone1' => array(
            'phone-a' => array(
                'required'   => true,
                'allowEmpty' => false,
                'last'       => true,
                'rule'       => 'notEmpty',
                'message'    => 'Please enter a phone number'
            ),
            'phone-b' => array(
                'last'       => true,
                'rule'    => array('numeric'),
                'message'    => 'Please enter a valid phone number'
           ),
            'phone-c' => array(
                'last'       => true,
                'rule'       => array('between',8, 12), 
                'message'    => 'Numbers only please'
            ),
        ),
                
        'phone2' => array(
            'phone-a' => array(
                'required'   => true,
                'allowEmpty' => true,
                'last'       => true,
                'rule'       => 'notEmpty',
                'message'    => 'Please enter a phone number'
            ),
            'phone-b' => array(
                'last'       => true,
                'rule'    => array('numeric'),
                'message'    => 'Please enter a valid phone number'
            ),
            'phone-c' => array(
                'last'       => true,
                'rule'       => array('between',8, 12), 
                'message'    => 'Numbers only please'
            ),
        ),
        
        
        'email' => array(
            'required'   => true,
            'allowEmpty' => false,
            'rule'    => array('email', true),
            'message' => 'Please supply a valid email address.'
        ),
        
        'pc'=> array(
            'rule' => array('postal', '/^[0-9]{4}$/'),
            'allowEmpty' => true,
            'message' => 'Please enter an Australian Postcode'
        ),
          
          
    );

/**
 * hasAndBelongsToMany associations
 *
 * @var array
 */
    public $hasMany = array(
        'Product' => array(
            'className' => 'Products',
            'foreignKey' => 'suppliers_id',
            'conditions' => '',
            'fields' => '',
            'order' => ''
        ),
        'Order' => array(
            'className' => 'Orders',
            'foreignKey' => 'suppliers_id',
            'conditions' => '',
            'fields' => '',
            'order' => ''
        )
    );

}